<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core">

<ui:composition template="template.xhtml">
	<ui:define name="corpo">
		<h:panelGroup id="painelGeral">
			<h:dataTable value="#{edicaoLivroMB.livros}" var="livro" border="2" cellspacing="2">
				<h:column>
					<f:facet name="header">Código</f:facet>
					#{livro.codigo}
				</h:column>
				<h:column>
					<f:facet name="header">#{msg.livro}</f:facet>
					#{livro.nome}
				</h:column>
				<h:column>
					<f:facet name="header">Preço</f:facet>
					#{livro.preco}
				</h:column>
				<h:column>
					<f:facet name="header">Categoria</f:facet>
					#{livro.categoria.nome}
				</h:column>
				<h:column>
					<f:facet name="header">Estoque</f:facet>
					#{livro.estoque}
				</h:column>
				<h:column>
					<f:facet name="header">Autor</f:facet>
					#{livro.autor.nome}
				</h:column>
				<h:column>
					<h:commandLink styleClass="icon-edit">
						<f:ajax render="@form" event="click" listener="#{edicaoLivroMB.alterar(livro)}"/>
					</h:commandLink>
					<h:commandLink styleClass="icon-remove">
						<f:ajax render="@form" event="click" listener="#{edicaoLivroMB.remove(livro)}"/>
					</h:commandLink>
				</h:column>
			</h:dataTable>
			<h:commandButton value="Novo" actionListener="#{edicaoLivroMB.novo}" styleClass="btn btn-large btn-primary" />
			<h2 class="form-signin-heading">Livro</h2>
	        Nome: <h:inputText value="#{edicaoLivroMB.livro.nome}"/><br />
	        Preço: <h:inputText value="#{edicaoLivroMB.livro.preco}"/><br />
	        Categoria: <h:selectOneMenu value="#{edicaoLivroMB.livro.categoria}" converter="converterCategoria">
	        	<f:selectItems value="#{edicaoLivroMB.categorias}" var="categoria" itemValue="#{categoria}" itemLabel="#{categoria.nome}" itemDescription="#{categoria.nome}"/>
	        </h:selectOneMenu><br />
	        Estoque: <h:inputText value="#{edicaoLivroMB.livro.estoque}"/><br />
	        Autor: <h:selectOneMenu value="#{edicaoLivroMB.livro.autor}" converter="converterAutor">
	        	<f:selectItems value="#{edicaoLivroMB.autores}" var="autor" itemValue="#{autor}" itemLabel="#{autor.nome}" itemDescription="#{autor.nome}"/>
	        </h:selectOneMenu><br />
			<h:commandButton value="Salvar" actionListener="#{edicaoLivroMB.salvarLivro}" styleClass="btn btn-large btn-primary" />
		</h:panelGroup>
	</ui:define>
</ui:composition>
</html>